<template>
	<div>
		<!-- xpert导航栏 -->
		<xpertNavBar :statusTab="statusTab" />
		<div style="height: 150px; width: 100%"></div>
		<div v-if="ind == 1" class="boxLogin f f-a-c f-j-c">
			<div class="topTit">
				<div class="name">Verification mailbox</div>
				<div class="count">We have sent an email to your mailbox, please enter the verification code in the email to confirm.</div>
				<div class="inpBox">
					<div class="inpTit">Verification code</div>
					<input type="text" class="inp" placeholder="Enter verification code" v-model="code" name="" id="" />
				</div>
				<!-- btn -->
				<div @click="endMessage" class="btn hand">Send reset link</div>
				<div class="botSignUp f f-a-c f-j-c">Don't have an account? <span class="hand">Sign up</span></div>
			</div>
		</div>
		<div v-else class="boxLogin f f-a-c f-j-c">
			<div class="topTitsss">A link to reset your password has been sent towx123456789@qq.com.</div>
		</div>
		<xpertTabbar />
	</div>
</template>

<script setup>
	import { ref, onMounted } from "vue";
	import { EmailCode, RegisterilCode } from "@/api/login.js";
	import { ElMessage } from "element-plus";
	import xpertTabbar from "@/components/tabBar/xpertTabbar.vue";
	import xpertNavBar from "@/components/navBar/xpertNavBar.vue";
	import router from "@/router/index.js";
	import ButtonDiffuse from "@/components/Button/ButtonDiffuse.vue";
	import { useRoute } from "vue-router";
	import { refrestTokenXP, refrestTokenKC } from "@/utils/setting.js";
	let statusTab = ref(1);
	let code = ref("");
	let route = useRoute();
	let act = route.query.act;
	let ind = ref(1);
	console.log(act, "11111111111111");
	onMounted(async () => {
		// 请求发送验证码
		let n = await EmailCode();
		if (n.code == 200) {
			ElMessage.success("Sent successfully");
		}
		// return;
		window.addEventListener("scroll", handleScroll);
	});
	const endMessage = async () => {
		let n = await RegisterilCode({ code: code.value });
		if (n.code == 200) {
			localStorage.setItem("logininfo", JSON.stringify(n.data));
			// 存储token
			localStorage.setItem("xpToken", n.data.accessTokenXp);
			localStorage.setItem("kcToken", n.data.accessTokenKc);
			ind.value = 2;
			ElMessage.success(n.msg);
			// 注册成功跳转login
			setTimeout(() => {
				if (act == "xp") {
					// 这里是把导航
					localStorage.setItem("ind", 3);
					// 跳转到xpert首页
					router.replace("/");
				} else if (act == "kc") {
					localStorage.setItem("ind", 6);
					// 跳转到knowclub首页
					router.replace("/KnowClub");
				}
			}, 3000);
		}
	};
	// 这个是当头部导航栏滑倒下面时给tabr加个背景
	const handleScroll = () => {
		const scrollTop = document.documentElement.scrollTop;
		if (scrollTop > 0) {
			statusTab.value = 2;
		} else {
			statusTab.value = 1;
		}
	};
</script>
<style scoped>
	@import "./index.scss";
</style>
